<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var date1 = new Date('2020-06-19  12:00:00');
        var date2 = new Date('2020-07-19 18:18:18')
        var time1 = date1.getTime();
        var time2 = date2.getTime();
        var chaTime = Math.abs(time1 - time2)
        var day = parseInt((chaTime / 1000) / 60 / 60 / 24)
        var h = parseInt((chaTime / 1000 / 60 / 60) % 24)
        var m = parseInt((chaTime / 1000 / 60) % 60)
        var s = parseInt(chaTime / 1000 % 60)
        console.log('两个时间相差' + day + '天' + h + '小时' + m + '分' + s + '秒')
    </script>
</body>

</html>